<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>创建联系人</title>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.0.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <h3 class="text-center text-warning">
                创建联系人信息
            </h3>

            <form id="connectorForm" class="form-horizontal" role="form">
                <h4>联系人基本信息</h4>

                <div class="form-group">
                    <label for="startDate" class="col-sm-2 control-label">机构名称:</label>
                    <div class="col-sm-7">
                        <input name="charityname" type="text" class="form-control"  />
                    </div>
                    <label for="targetLand" class="col-sm-3 control-label"></label>
                </div>
                <div class="form-group">
                    <label for="startDate" class="col-sm-2 control-label">姓名:</label>
                    <div class="col-sm-7">
                        <input name="name" type="text" class="form-control"  />
                    </div>
                    <label for="targetLand" class="col-sm-3 control-label"></label>
                </div>

                <div class="form-group">
                    <label for="startDate" class="col-sm-2 control-label">性别:</label>
                    <div class="col-sm-7">
                            <input type="radio" name="sex" value="1">男&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="radio" name="sex" value="2">女
                    </div>
                    <label for="targetLand" class="col-sm-3 control-label"></label>
                </div>

                <div class="form-group">
                    <label for="startDate" class="col-sm-2 control-label">职务:</label>
                    <div class="col-sm-7">
                        <input name="duty" type="text" class="form-control"  />
                    </div>
                    <label for="targetLand" class="col-sm-3 control-label"></label>
                </div>

                <div class="form-group">
                    <label for="startDate" class="col-sm-2 control-label">手机:</label>
                    <div class="col-sm-7">
                        <input id="telephone" name="telephone" type="text" class="form-control"  />
                    </div>
                    <label for="targetLand" class="col-sm-3 control-label"></label>
                </div>

                <div class="form-group">
                    <label for="startDate" class="col-sm-2 control-label">办公电话:</label>
                    <div class="col-sm-7">
                        <input name="phone" type="text" class="form-control"  />
                    </div>
                    <label for="targetLand" class="col-sm-3 control-label"></label>
                </div>

                <div class="form-group">
                    <label for="startDate" class="col-sm-2 control-label">邮箱:</label>
                    <div class="col-sm-7">
                        <input id="email" name="email" type="email" class="form-control"  />
                    </div>
                    <label for="targetLand" class="col-sm-3 control-label"></label>
                </div>

                <div class="form-group">
                    <label for="startDate" class="col-sm-2 control-label">QQ:</label>
                    <div class="col-sm-7">
                        <input id="qq" name="qq" type="text" class="form-control"  />
                    </div>
                    <label for="targetLand" class="col-sm-3 control-label"></label>
                </div>

                <div class="form-group">
                    <label for="startDate" class="col-sm-2 control-label">地址:</label>
                    <div class="col-sm-7">
                        <input name="address" type="text" class="form-control"  />
                    </div>
                    <label for="targetLand" class="col-sm-3 control-label"></label>
                </div>

                <div class="form-group">
                    <label for="targetLand" class="col-sm-2 control-label">重要等级:</label>
                    <div class="col-sm-7">
                        <select id="targetLand" name="impgrade" class="form-control">
                            <option value="-1" selected>--请选择--</option>
                            <#list impList as imp>
                                <option value="${imp.id}">${imp.impname}</option>
                            </#list>
                        </select>
                    </div>
                    <label for="targetLand" class="col-sm-3 control-label"></label>
                </div>

                <div class="form-group">
                    <label for="targetLand" class="col-sm-2 control-label">跟进状态:</label>
                    <div class="col-sm-7">
                        <select id="targetLand" name="followstatus" class="form-control">
                            <option value="-1" selected>--请选择--</option>
                            <#list followList as follow>
                                <option value="${follow.id}">${follow.followname}</option>
                            </#list>
                        </select>
                    </div>
                    <label for="targetLand" class="col-sm-3 control-label"></label>
                </div>


                <div class="form-group">
                    <label for="startDate" class="col-sm-2 control-label">经办人</label>
                    <div class="col-sm-7">
                        <input id="startDate" name="operator" type="text" class="form-control"  />
                    </div>
                    <label for="targetLand" class="col-sm-3 control-label"></label>
                </div>

                <div class="form-group">
                    <label for="startDate" class="col-sm-2 control-label">是否认可:</label>
                    <div class="col-sm-7">
                        <input type="radio" name="accept" value="1">是&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="accept" value="0">否
                    </div>
                    <label for="targetLand" class="col-sm-3 control-label"></label>
                </div>

                <div class="form-group">
                    <label for="remark" class="col-sm-2 control-label">认可理由</label>
                    <div class="col-sm-7">
                        <textarea id="reason" name="reason"  class="form-control" ></textarea>
                    </div>
                    <label for="remark" class="col-sm-3 control-label"></label>
                </div>

                <div class="form-group">
                    <label for="remark" class="col-sm-2 control-label">备注</label>
                    <div class="col-sm-7">
                        <textarea id="remake" name="remake"  class="form-control" ></textarea>
                    </div>
                    <label for="remark" class="col-sm-3 control-label"></label>
                </div>

                <span id="addSpan"></span>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="button" onclick="connectorSub()" class="btn btn-info">添加</button>
                        <button type="button" onclick="history.back()" class="btn btn-info">返回</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="/js/jquery.js"></script>
<script>

    //校验邮箱格式
    $("#email").blur(function () {
        var email=$(this).val();
        var pattern = /^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
        if (!pattern.test(email)) {
            alert("邮箱格式不正确");
            return false;
        }

    });

    //校验手机号
    $("#telephone").blur(function () {
        var phone = $("#telephone").val();
        var regex = /^(13[0-9]{9})|(15[0-9]{9})|(17[0-9]{9})|(18[0-9]{9})|(19[0-9]{9})$/;
        if (!regex.test(phone)) {
            alert("请录入正确的手机号码！");
            return false;
        }
    });

    //校验QQ号  /^[1-9]\d{5,11}$/
    $("#qq").blur(function () {
        var qq = $("#qq").val();
        var regex = /^[1-9]\d{5,11}$/;
        if (!regex.test(qq)) {
            alert("请录入正确的QQ号码！");
            return false;
        }
    });

        // 添加全部信息
    function connectorSub(){
        //1. 获取form表单中的全部内容
        var data = $("#connectorForm").serialize(); // 将携带name属性的表单项拼接为key=value&key=value..
        //2. 发送ajax请求到后台,并传递全部的参数.
        $.post(
            "/connector/addConnector",
            data,
            function(result){
                if(result.code == 0){
                    alert("添加成功");
                    location.href = "/connector/findAll";
                }else{
                    $("#addSpan").html(result.msg).css("color","red");
                }
            },
            "json"
        );
    }

</script>
</body>
</html>